﻿/// <reference name="MicrosoftAjax.js"/>
/// <reference name="GSC.WebControls.js"/>
Type.registerNamespace("GSC.WebControls");
GSC.WebControls.AsyncListLoadingWaitControl = function(element) {
    GSC.WebControls.AsyncListLoadingWaitControl.initializeBase(this, [element]);
    this._fillWindowColor = '#000000';
    this._opacity = 0.6;
    this._loadingText = '';
    this._loadingImage = '';
    this._speed = 0;
    this._zIndex = 10000;
    this._starts = 0.01;
    this._degenerating = 0;
}
GSC.WebControls.AsyncListLoadingWaitControl.prototype = {
    initialize: function() {
        GSC.WebControls.AsyncListLoadingWaitControl.callBaseMethod(this, 'initialize');
        //验证是否第一次初始化。
        if (window.AsyncListLoadingWaitControl === null || window.AsyncListLoadingWaitControl === undefined) {
            //创建控件对象。
            window.AsyncListLoadingWaitControl = document.createElement("div");
            //设置初始化预置值。
            window.AsyncListLoadingWaitControl._Control = this;
            window.AsyncListLoadingWaitControl._elementID = this.get_id();
            window.AsyncListLoadingWaitControl._asyncIDs = this._asyncIDs;
            window.AsyncListLoadingWaitControl._speed = this._speed;
            window.AsyncListLoadingWaitControl._starts = this._starts;
            window.AsyncListLoadingWaitControl._opacity = this._opacity;
            window.AsyncListLoadingWaitControl._degenerating = this._degenerating;
            window.AsyncListLoadingWaitControl._loadingText = this._loadingText;
            window.AsyncListLoadingWaitControl._loadingImage = this._loadingImage;
            window.AsyncListLoadingWaitControl._isWait = false;
            //设置控件元素ID。
            window.AsyncListLoadingWaitControl.id = this.get_id() + '_FillWindow';
            //验证是否为IE6浏览器。
            if (Sys.Browser.agent == Sys.Browser.InternetExplorer && Sys.Browser.version == 6)
                window.AsyncListLoadingWaitControl._isIE6 = true;
            else
                window.AsyncListLoadingWaitControl._isIE6 = false;
            //设置控件元素透明度。
            GuoShuCan.SDK.Web.Style.DX.Alpha(window.AsyncListLoadingWaitControl, 0);
            //设置控件元素样式。
            with (window.AsyncListLoadingWaitControl.style) {
                overflow = 'hidden';
                backgroundColor = this._fillWindowColor;
                position = window.AsyncListLoadingWaitControl._isIE6 ? 'absolute' : 'fixed';
                zIndex = this._zIndex;
                display = 'none';
                left = '0px';
                top = '0px';
            }
            document.body.appendChild(window.AsyncListLoadingWaitControl);
            if (window.AsyncListLoadingWaitControl._isIE6) {
                window.AsyncListLoadingWaitControl._ie6Iframe = document.createElement("iframe");
                GuoShuCan.SDK.Web.Style.DX.Alpha(window.AsyncListLoadingWaitControl._ie6Iframe, 0.01);
                with (window.AsyncListLoadingWaitControl._ie6Iframe.style) {
                    zIndex = this._zIndex + 1;
                    left = '0px';
                    top = '0px';
                    backgroundColor = this._fillWindowColor;
                    display = 'none';
                }
                with (window.AsyncListLoadingWaitControl._ie6Iframe) {
                    id = this.get_id() + '_FillWindow_IE6Iframe';
                    tframeborder = 0;
                    scrolling = 'no';
                    marginheight = 0;
                    marginwidth = 0;
                }
                window.AsyncListLoadingWaitControl.appendChild(window.AsyncListLoadingWaitControl._ie6Iframe);
            }
            window.AsyncListLoadingWaitControl._showLoading = document.createElement("div");
            with (window.AsyncListLoadingWaitControl._showLoading.style) {
                zIndex = this._zIndex + 2;
                position = window.AsyncListLoadingWaitControl._isIE6 ? 'absolute' : 'fixed';
                padding = '2px';
                border = '1px dotted #000000';
                display = 'none';
            }
            window.AsyncListLoadingWaitControl._showLoading.id = this.get_id() + '_Loading';
            //
            window.AsyncListLoadingWaitControl._showLoadingTransparent = document.createElement("div");
            with (window.AsyncListLoadingWaitControl._showLoadingTransparent.style) {
                zIndex = this._zIndex + 2;
                position = window.AsyncListLoadingWaitControl._isIE6 ? 'absolute' : 'fixed';
                backgroundColor = '#4aa5ff';
                display = 'none';

            }
            window.AsyncListLoadingWaitControl._showLoadingTransparent.id = this.get_id() + '_Loading_Transparent';
            //GuoShuCan.SDK.Web.Style.DX.Alpha(window.AsyncListLoadingWaitControl._showLoadingTransparent, 0.1);
            //
            window.AsyncListLoadingWaitControl._showLoadingImage = document.createElement("img");
            window.AsyncListLoadingWaitControl._showLoadingImage.id = window.AsyncListLoadingWaitControl._showLoading.id + '_Image';
            window.AsyncListLoadingWaitControl._showLoadingImage.src = window.AsyncListLoadingWaitControl._loadingImage;
            window.AsyncListLoadingWaitControl._showLoading.appendChild(window.AsyncListLoadingWaitControl._showLoadingImage);
            window.AsyncListLoadingWaitControl._showLoadingSpan = document.createElement("span");
            window.AsyncListLoadingWaitControl._showLoadingSpan.id = window.AsyncListLoadingWaitControl._showLoading.id + '_Span';
            window.AsyncListLoadingWaitControl._showLoadingSpan.innerText = ' ' + this._loadingText;
            window.AsyncListLoadingWaitControl._showLoadingSpan.style.fontSize = '12px';
            window.AsyncListLoadingWaitControl._showLoading.appendChild(window.AsyncListLoadingWaitControl._showLoadingSpan);
            document.body.appendChild(window.AsyncListLoadingWaitControl._showLoadingTransparent);
            document.body.appendChild(window.AsyncListLoadingWaitControl._showLoading);
            //
            window.AsyncListLoadingWaitControl._onLayout = function() {
                window.AsyncListLoadingWaitControl._clientBounds = GuoShuCan.SDK.Web.DomElement.getClientBounds();
                var top = 0, left = 0;
                if (window.AsyncListLoadingWaitControl._isIE6) {
                    top = document.documentElement.scrollTop;
                    left = document.documentElement.scrollLeft;
                    window.AsyncListLoadingWaitControl.style.top = top.toString() + 'px';
                    window.AsyncListLoadingWaitControl.style.left = left.toString() + 'px';
                    window.AsyncListLoadingWaitControl._ie6Iframe.style.top = top.toString() + 'px';
                    window.AsyncListLoadingWaitControl._ie6Iframe.style.left = left.toString() + 'px';
                    window.AsyncListLoadingWaitControl._ie6Iframe.style.width = window.AsyncListLoadingWaitControl._clientBounds.width.toString() + 'px';
                    window.AsyncListLoadingWaitControl._ie6Iframe.style.height = window.AsyncListLoadingWaitControl._clientBounds.height.toString() + 'px';
                }
                window.AsyncListLoadingWaitControl.style.width = window.AsyncListLoadingWaitControl._clientBounds.width.toString() + 'px';
                window.AsyncListLoadingWaitControl.style.height = window.AsyncListLoadingWaitControl._clientBounds.height.toString() + 'px';
                if (window.AsyncListLoadingWaitControl._showLoading.style.display != 'none') {
                    window.AsyncListLoadingWaitControl._showLoading.style.left = parseInt((window.AsyncListLoadingWaitControl._clientBounds.width / 2) - (window.AsyncListLoadingWaitControl._showLoading.clientWidth / 2)).toString() + 'px';
                    if (window.AsyncListLoadingWaitControl._isIE6) {
                        window.AsyncListLoadingWaitControl._showLoading.style.top = parseInt((window.AsyncListLoadingWaitControl._clientBounds.height / 2) - (window.AsyncListLoadingWaitControl._showLoading.clientHeight / 2) + top).toString() + 'px';
                    } else {
                        window.AsyncListLoadingWaitControl._showLoading.style.top = parseInt((window.AsyncListLoadingWaitControl._clientBounds.height / 2) - (window.AsyncListLoadingWaitControl._showLoading.clientHeight / 2)).toString() + 'px';
                    }
                    window.AsyncListLoadingWaitControl._showLoadingTransparent.style.left = window.AsyncListLoadingWaitControl._showLoading.style.left;
                    window.AsyncListLoadingWaitControl._showLoadingTransparent.style.top = window.AsyncListLoadingWaitControl._showLoading.style.top;
                }
            }
            //注册异步控件事件。
            window.AsyncListLoadingWaitControl._registerControl = function() {
                window.AsyncListLoadingWaitControl._clickHandlers = [];
                for (var i = 0; i < window.AsyncListLoadingWaitControl._asyncIDs.length; i++) {
                    if (window.AsyncListLoadingWaitControl._asyncIDs[i] == null) {
                        window.AsyncListLoadingWaitControl._clickHandlers[i] = null;
                    }
                    else {
                        var e = $get(window.AsyncListLoadingWaitControl._asyncIDs[i]);
                        if (e == null)
                            window.AsyncListLoadingWaitControl._clickHandlers[i] = null;
                        else {
                            if (e.getAttribute('disabled') !== 'disabled') {
                                window.AsyncListLoadingWaitControl._clickHandlers[i] = Function.createDelegate(window, window.AsyncListLoadingWaitControl._onClick);
                                if (e.tagName == 'SELECT')
                                    $addHandler(e, 'change', window.AsyncListLoadingWaitControl._clickHandlers[i]);
                                else
                                    $addHandler(e, 'click', window.AsyncListLoadingWaitControl._clickHandlers[i]);
                            }
                        }
                    }
                }
            }
            //卸载异步控件事件。
            window.AsyncListLoadingWaitControl._uninstallControl = function() {
                if (window.AsyncListLoadingWaitControl._asyncIDs.length > 0 && window.AsyncListLoadingWaitControl._clickHandlers != null) {
                    for (var i = 0; i < window.AsyncListLoadingWaitControl._asyncIDs.length; i++) {
                        if (window.AsyncListLoadingWaitControl._asyncIDs[i] != null) {
                            var e = $get(window.AsyncListLoadingWaitControl._asyncIDs[i]);
                            if (e != null) {
                                if (e.getAttribute('disabled') !== 'disabled') {
                                    if (e.tagName == 'SELECT')
                                        $removeHandler(e, 'change', window.AsyncListLoadingWaitControl._clickHandlers[i]);
                                    else
                                        $removeHandler(e, 'click', window.AsyncListLoadingWaitControl._clickHandlers[i]);
                                    window.AsyncListLoadingWaitControl._clickHandlers[i] = null;
                                }
                            }
                        }
                    }
                    //delete window.AsyncListLoadingWaitControl._clickHandlers;
                }
            }
            //
            window.AsyncListLoadingWaitControl._onClick = function(e) {
                if (window.AsyncListLoadingWaitControl._isWait) return;
                window.AsyncListLoadingWaitControl._isWait = true;
                switch (e.target.tagName) {
                    case 'A': break;
                    case 'INPUT': break;
                    case 'SELECT': break;
                    default: return;
                }
                //
                //GuoShuCan.SDK.Web.Style.DX.Alpha(window.AsyncListLoadingWaitControl, 0);
                window.AsyncListLoadingWaitControl.style.display = '';
                window.AsyncListLoadingWaitControl._showLoading.style.display = '';
                window.AsyncListLoadingWaitControl._showLoadingTransparent.style.display = '';
                //
                window.AsyncListLoadingWaitControl._showLoadingTransparent.style.width = window.AsyncListLoadingWaitControl._showLoading.clientWidth.toString() + 'px';
                window.AsyncListLoadingWaitControl._showLoadingTransparent.style.height = window.AsyncListLoadingWaitControl._showLoading.clientHeight.toString() + 'px';
                window.AsyncListLoadingWaitControl._onLayout();
                var mm = null;
                window.AsyncListLoadingWaitControl._currentOpacity = 0;
                var f = Function.createDelegate(window, function() {
                    window.AsyncListLoadingWaitControl._currentOpacity += window.AsyncListLoadingWaitControl._starts;
                    if (window.AsyncListLoadingWaitControl._currentOpacity >= window.AsyncListLoadingWaitControl._opacity) {
                        return;
                    } else {
                        if (Sys.Browser.agent === Sys.Browser.Firefox || Sys.Browser.Opera) {
                            if (window.AsyncListLoadingWaitControl._currentOpacity > 1) {
                                window.AsyncListLoadingWaitControl._currentOpacity = 1;
                            }
                        }
                       // GuoShuCan.SDK.Web.Style.DX.Alpha(window.AsyncListLoadingWaitControl, window.AsyncListLoadingWaitControl._currentOpacity);
                        mm = window.setTimeout(f, window.AsyncListLoadingWaitControl._speed);
                    }
                });
                mm = window.setTimeout(f, window.AsyncListLoadingWaitControl._speed);
            }
            //
            window.AsyncListLoadingWaitControl._onWindowResize = function(e) { window.AsyncListLoadingWaitControl._onLayout(); };
            window.AsyncListLoadingWaitControl._windowResizeHandler = Function.createDelegate(window, window.AsyncListLoadingWaitControl._onWindowResize);
            $addHandler(window, 'resize', window.AsyncListLoadingWaitControl._windowResizeHandler);
            $addHandler(window, 'scroll', window.AsyncListLoadingWaitControl._windowResizeHandler);
            //
            window.AsyncListLoadingWaitControl._initializeRequest = function(sender, args) {
            }
            window.AsyncListLoadingWaitControl._initializeRequestHandler = Function.createDelegate(window, window.AsyncListLoadingWaitControl._initializeRequest);
            Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(window.AsyncListLoadingWaitControl._initializeRequestHandler);
            //
            window.AsyncListLoadingWaitControl._beginRequest = function(sender, args) {
                //注销事件。
                window.AsyncListLoadingWaitControl._uninstallControl();
            }
            window.AsyncListLoadingWaitControl._beginRequestHandler = Function.createDelegate(window, window.AsyncListLoadingWaitControl._beginRequest);
            Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(window.AsyncListLoadingWaitControl._beginRequestHandler);
            window.AsyncListLoadingWaitControl._endRequest = function(sender, args) {
            }
            window.AsyncListLoadingWaitControl._endRequestHandler = Function.createDelegate(window, window.AsyncListLoadingWaitControl._endRequest);
            Sys.WebForms.PageRequestManager.getInstance().add_endRequest(window.AsyncListLoadingWaitControl._endRequestHandler);
            window.AsyncListLoadingWaitControl._pageLoading = function(sender, args) {
            }
            window.AsyncListLoadingWaitControl._pageLoadingHandler = Function.createDelegate(window, window.AsyncListLoadingWaitControl._pageLoading);
            Sys.WebForms.PageRequestManager.getInstance().add_pageLoading(window.AsyncListLoadingWaitControl._pageLoadingHandler);
            //
            window.AsyncListLoadingWaitControl._pageLoaded = function(sender, args) {
                var dataItems = undefined;
                if (args.get_dataItems()[window.AsyncListLoadingWaitControl._elementID] != undefined) {
                    dataItems = args.get_dataItems()[window.AsyncListLoadingWaitControl._elementID].split('|');
                }
                if (dataItems == undefined) {
                    for (var i = 0; i < window.AsyncListLoadingWaitControl._asyncIDs.length; i++) {
                        if (args.get_dataItems()[window.AsyncListLoadingWaitControl._asyncIDs[i]] != undefined) {
                            dataItems = args.get_dataItems()[window.AsyncListLoadingWaitControl._asyncIDs[i]].split('|');
                            break;
                        }
                    }
                }
                if (dataItems == undefined) {
                    //window.AsyncListLoadingWaitControl._registerControl();
                }
                //if (dataItems[0] == '__GSC__AsyncListLoadingWaitControlUpdateComplete') {
                    var mm = null;
                    var f = Function.createDelegate(window, function() {
                        if (window.AsyncListLoadingWaitControl._degenerating > 0)
                            window.AsyncListLoadingWaitControl._currentOpacity -= window.AsyncListLoadingWaitControl._degenerating;
                        else
                            window.AsyncListLoadingWaitControl._currentOpacity -= 0.1;
                        if (Sys.Browser.agent === Sys.Browser.Firefox || Sys.Browser.Opera) {
                            if (window.AsyncListLoadingWaitControl._currentOpacity < 0) {
                                window.AsyncListLoadingWaitControl._currentOpacity = 0;
                            }
                        }
                       // GuoShuCan.SDK.Web.Style.DX.Alpha(window.AsyncListLoadingWaitControl, window.AsyncListLoadingWaitControl._currentOpacity);
                        if (window.AsyncListLoadingWaitControl._currentOpacity <= 0) {
                            window.AsyncListLoadingWaitControl.style.display = 'none';
                            window.AsyncListLoadingWaitControl._showLoading.style.display = 'none';
                            window.AsyncListLoadingWaitControl._showLoadingTransparent.style.display = 'none';
                            //delete window.AsyncListLoadingWaitControl._asyncIDs;
                            window.AsyncListLoadingWaitControl._asyncIDs = window.AsyncListLoadingWaitControl._Control._asyncIDs;
                            window.AsyncListLoadingWaitControl._registerControl();
                            window.AsyncListLoadingWaitControl._isWait = false;
                            return;
                        } else {
                            mm = window.setTimeout(f, window.AsyncListLoadingWaitControl._speed);
                        }
                    });
                    mm = window.setTimeout(f, window.AsyncListLoadingWaitControl._speed);
                //}
            }
            //注册异步操作控件点击事件。
            window.AsyncListLoadingWaitControl._registerControl();
            //注册页面回调加载后事件。
            window.AsyncListLoadingWaitControl._pageLoadedHandler = Function.createDelegate(window, window.AsyncListLoadingWaitControl._pageLoaded);
            Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(window.AsyncListLoadingWaitControl._pageLoadedHandler);
        } else {
            //设置初始化预置值。
            //delete window.AsyncListLoadingWaitControl._Control;
            window.AsyncListLoadingWaitControl._Control = this;
            //delete window.AsyncListLoadingWaitControl._speed;
            window.AsyncListLoadingWaitControl._speed = this._speed;
            //delete window.AsyncListLoadingWaitControl._starts;
            window.AsyncListLoadingWaitControl._starts = this._starts;
            //delete window.AsyncListLoadingWaitControl._opacity;
            window.AsyncListLoadingWaitControl._opacity = this._opacity;
            //delete window.AsyncListLoadingWaitControl._degenerating;
            window.AsyncListLoadingWaitControl._degenerating = this._degenerating;
            //delete window.AsyncListLoadingWaitControl._loadingText;
            window.AsyncListLoadingWaitControl._loadingText = this._loadingText;
            //delete window.AsyncListLoadingWaitControl._loadingImage;
            window.AsyncListLoadingWaitControl._loadingImage = this._loadingImage;
            window.AsyncListLoadingWaitControl._showLoadingSpan.innerText = ' ' + this._loadingText;
            window.AsyncListLoadingWaitControl._showLoadingImage.src = window.AsyncListLoadingWaitControl._loadingImage;
        }
    },
    //释放资源。
    dispose: function() { GSC.WebControls.AsyncListLoadingWaitControl.callBaseMethod(this, 'dispose'); /*CollectGarbage();*/ },
    //透明度。
    get_Opacity: function() { return this._opacity; },
    set_Opacity: function(v) { this._opacity = v; },
    //异步操作ID集合。
    get_AsyncIDs: function() { return this._asyncIDs; },
    set_AsyncIDs: function(v) { this._asyncIDs = v; },
    //遮盖层原色。
    get_FillWindowColor: function() { return this._fillWindowColor; },
    set_FillWindowColor: function(v) { this._fillWindowColor = v; },
    //加载状态图标。
    get_LoadingImage: function() { return this._loadingImage; },
    set_LoadingImage: function(v) { this._loadingImage = v; },
    //渐变速度。
    get_Speed: function() { return this._speed; },
    set_Speed: function(v) { this._speed = v; },
    //加载状态内容。
    get_LoadingText: function() { return this._loadingText; },
    set_LoadingText: function(v) { this._loadingText = v; },
    //渐现值。
    get_Starts: function() { return this._starts; },
    set_Starts: function(v) { this._starts = v; },
    //渐退值。
    get_Degenerating: function() { return this._degenerating; },
    set_Degenerating: function(v) { this._degenerating = v; }
}
GSC.WebControls.AsyncListLoadingWaitControl.registerClass('GSC.WebControls.AsyncListLoadingWaitControl', Sys.UI.Control);
if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();